<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script>

$(function()
{
	
});

function save_click()
{
	var obj = $.getObject("#div_form");
	var urlIds = new Array();
	
	$.each($("#div_form :checkbox:checked"), function(i, obj)
	{
		var $obj = $(obj);
		var type = $obj.attr("name");
		if (type == "urlId")
		{
			urlIds.push($obj.val());
		}
	});
	
	if (urlIds.length == 0)
	{
		$.errorAlert("至少选择一个链接");
		return;
	}
	
	obj.urlIds = urlIds.join(",");
	$.simpleAjax("/base/open/role_url_save", obj, function(o)
	{
		$.successAlert("保存成功", "save_success()", 2000);
	});

}
function save_success()
{
	window.location = "${path}/base/open/role_list";
}

function url_select(id, type)
{
	if (type == 0) // 全选
	{
		$("div[parent_id="+id+"] :checkbox").prop("checked", true);
		$("#chk_url_"+id).prop("checked", true);
	}
	else if (type == 1) // 全不选
	{
		$("div[parent_id="+id+"] :checkbox").prop("checked", false);
		$("#chk_url_"+id).prop("checked", false);
	}
}


</script>

<div class="am-form am-form-horizontal am-cf am-margin" id="div_form">
<input type="hidden" name="roleId" value="${model.id!}"/>

	<fieldset>
		<legend>修改角色权限－${model.name!}</legend>
		
		<#assign root=treeList["0"]! />
		<#if root??>
		<#list root as vo>
		<div class="am-checkbox input_big">
			<label>
				<input type="checkbox" id="chk_url_${vo.id}" name="urlId" value="${vo.id}" <#if vo.select==0>checked</#if> /> ${vo.name!}
			</label>
			<a href="javascript:void(0)" class="am-margin-left-xl" onclick="url_select('${vo.id}', 0)">（全选</a>
			<a href="javascript:void(0)" class="am-margin-left" onclick="url_select('${vo.id}', 1)">全不选）</a>
		</div>
		
		<#assign sub=treeList[vo.id?string]! />
		<div class="am-form-group input_normal am-margin-left" parent_id="${vo.id}">
		<#if sub??>
		<#list sub as voo>
			<label class="am-checkbox-inline">
				<input type="checkbox" name="urlId" value="${voo.id}" <#if voo.select==0>checked</#if>> ${voo.name}
			</label>
		</#list>
		</#if>
		</div>
		
		</#list>
		</#if>
		<div class="am-u-md-12 am-text-center div_btn">
			<a href="javascript:void(0)" onclick="save_click()" class="am-btn am-btn-primary am-radius">保存</a>
			<a href="javascript:void(0)" onclick="save_success()" class="am-btn am-btn-default am-radius am-margin-left">返回</a>
		</div>
	</fieldset>
</div>

<#include "/layout/footer.ftl" />